# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


class BossPipeline(object):
    def process_item(self, item, spider):
        return item

import pymysql
class MysqlPipeline(object):
    def open_spider(self, spider):
        # 开启数据库连接
        self.conn = pymysql.connect('127.0.0.1', 'root', '123456', 'zhaopin', charset='utf8')
        self.cursor = self.conn.cursor()

    def process_item(self, item, spider):

        # # 存储数据
        # try:
        sql, data = item.get_sql()
        self.cursor.execute(sql, data)
        self.conn.commit()
        # except Exception as e:
        #     print(e)

        return item

    def close_spider(self, spider):
        self.cursor.close()
        self.conn.close()